package leetcode_401_500;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

public class LeeCode_409 {
    public static void main(String[] args) {

    }
    private static int longestPalindrome(String s) {
        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (map.containsKey(c)){
                map.put(c, map.get(c) + 1);
            }else {
                map.put(c, 1);
            }
        }
        boolean flag = false;
        int ans = 0;
        for (Character key : map.keySet()) {
            int count = map.get(key);
            if (count % 2 == 1){
                flag = true;
            }
            ans += (count / 2) * 2;
        }
        return ans + (flag ? 1 : 0);
    }
}
